package com.foodapp.back.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.foodapp.back.common.Result;
import com.foodapp.back.service.DishService;
import com.foodapp.back.service.RestaurantService;
import com.foodapp.back.vo.DishVO;
import com.foodapp.back.vo.RestaurantVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 餐厅控制器
 */
@RestController
@RequestMapping("/restaurant")
public class RestaurantController {

    @Resource
    private RestaurantService restaurantService;
    
    @Resource
    private DishService dishService;

    /**
     * 分页查询餐厅列表
     */
    @GetMapping("/list")
    public Result<Page<RestaurantVO>> list(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String category,
            @RequestParam(required = false) String keyword) {
        
        Page<RestaurantVO> result = restaurantService.pageList(page, size, category, keyword);
        return Result.success(result);
    }

    /**
     * 获取餐厅详情
     */
    @GetMapping("/{id}")
    public Result<RestaurantVO> getById(@PathVariable Long id) {
        RestaurantVO restaurantVO = restaurantService.getRestaurantById(id);
        return Result.success(restaurantVO);
    }

    /**
     * 获取餐厅菜单
     */
    @GetMapping("/{id}/menu")
    public Result<List<DishVO>> getMenu(@PathVariable Long id) {
        List<DishVO> menu = dishService.getMenuByRestaurantId(id);
        return Result.success(menu);
    }
}
